﻿using System;
using System.Collections.Generic;

using System.Text;
using System.Data;
using System.Data.SqlClient;
using Manager.DataAccess;

namespace Manager.DataAccess
{
    public class DataRoom
    {
        public string MaPhong { get; set; }
        public int MaTang { get; set; }
        public string DienThoai { get; set; }
        public string TenPhong { get; set; }
        public string LoaiPhong { get; set; }
        public string TinhTrang { get; set; }
        public string GhiChu { get; set; }
        public int ViTri { get; set; }

        AccessData ac = new AccessData();
        SqlCommand cmd;
        static SqlConnection conn;

        static DataRoom()
        {
            conn = AccessData.GetConnect();
        }
        public void Insert(DataRoom dt)
        {
            if (conn.State == ConnectionState.Closed) conn.Open();
            cmd = new SqlCommand("SP_Phong_Insert", conn);
            cmd.CommandType = CommandType.StoredProcedure;
            cmd.Parameters.Add("@MaPhong", SqlDbType.NVarChar).Value = dt.MaPhong;
            cmd.Parameters.Add("@MaTang", SqlDbType.Int).Value = dt.MaTang;
            cmd.Parameters.Add("@DienThoai", SqlDbType.NVarChar).Value = dt.DienThoai;
            cmd.Parameters.Add("@TenPhong", SqlDbType.NVarChar).Value = dt.TenPhong;
            cmd.Parameters.Add("@LoaiPhong", SqlDbType.NVarChar).Value = dt.LoaiPhong;
            cmd.Parameters.Add("@TinhTrang", SqlDbType.NVarChar).Value = dt.TinhTrang;
            cmd.Parameters.Add("@GhiChu", SqlDbType.NVarChar).Value = dt.GhiChu;
            cmd.Parameters.Add("@ViTri", SqlDbType.Int).Value = dt.ViTri;
            cmd.ExecuteNonQuery();
            cmd.Dispose();
        }
        public void Update(DataRoom dt)
        {
            cmd = new SqlCommand("SP_Phong_Update", conn);
            cmd.CommandType = CommandType.StoredProcedure;
            cmd.Parameters.Add("@MaPhong", SqlDbType.NVarChar).Value = dt.MaPhong;
            cmd.Parameters.Add("@MaTang", SqlDbType.Int).Value = dt.MaTang;
            cmd.Parameters.Add("@DienThoai", SqlDbType.NVarChar).Value = dt.DienThoai;
            cmd.Parameters.Add("@TenPhong", SqlDbType.NVarChar).Value = dt.TenPhong;
            cmd.Parameters.Add("@LoaiPhong", SqlDbType.NVarChar).Value = dt.LoaiPhong;
            cmd.Parameters.Add("@TinhTrang", SqlDbType.NVarChar).Value = dt.TinhTrang;
            cmd.Parameters.Add("@GhiChu", SqlDbType.NVarChar).Value = dt.GhiChu;
            cmd.Parameters.Add("@ViTri", SqlDbType.Int).Value = dt.ViTri;
            cmd.ExecuteNonQuery();
            cmd.Dispose();
        }
        public void Delete(DataRoom dt)
        {
            cmd = new SqlCommand("SP_Phong_Delete", conn);
            cmd.CommandType = CommandType.StoredProcedure;
            cmd.Parameters.Add("@MaPhong", SqlDbType.NVarChar).Value = dt.MaPhong;
            cmd.ExecuteNonQuery();
            cmd.Dispose();
            conn.Close();
        }
        public DataTable GetAll()
        {
            SqlDataAdapter adapter = new SqlDataAdapter("SP_Phong_SelectAll", conn);
            DataTable table = new DataTable();
            adapter.Fill(table);
            adapter.Dispose();
            return table;
        }
        public DataTable GetByID(DataRoom dt)
        {
            cmd = new SqlCommand("SP_Phong_GetByID", conn);
            cmd.CommandType = CommandType.StoredProcedure;
            cmd.Parameters.Add("@MaPhong", SqlDbType.NVarChar).Value = dt.MaPhong;
            SqlDataAdapter adapter = new SqlDataAdapter(cmd);
            DataTable table = new DataTable();
            adapter.Fill(table);
            cmd.Dispose();
            adapter.Dispose();
            return table;
        }
    }
}
